local data = rtos.buildDate()

local spi_flash = spi.deviceSetup(0,20,0,0,8,20*1000*1000,spi.MSB,1,0)
check_eq(sfud.init(spi_flash),true,"sfud init failed")
local sfud_device = sfud.getDeviceTable()
check_eq(sfud.write(sfud_device,1024,data),0,"sfud write failed")
check_eq(sfud.read(sfud_device,1024,#data),data,"sfud read not correct")
check_eq(sfud.mount(sfud_device,"/sfud"),true,"sfud mount failed")

-- 读写文件
for i = 1, 10, 1 do
    local f = io.open("/sfud/T", "wb")
    check_nil(f)
    local data = rtos.buildDate()
    f:write(data)
    f:close()
    f = io.open("/sfud/T", "rb")
    check_nil(f)
    check_eq(f:read("a"), data)
    f:close()
end

-- 快捷读写文件
for i = 1, 10, 1 do
    os.remove("/sfud/T")
    local data = rtos.buildDate()
    check_nil(io.writeFile("/sfud/T", data,"wb"))
    check_eq(io.readFile("/sfud/T"),data)
    check_eq(io.fileSize("/sfud/T"), #data)
end
